package com.cyz.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyz.dao.UserDao;
import com.cyz.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 *
 *
 * @author chenyizhen
 * @email sunlightcs@gmail.com
 * @date 2023-12-18 15:02:10
 */
@RestController
@RequestMapping("user/user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @PostMapping("/sign")
    public String sign(String account, String pwd){
        UserEntity entity = userDao.selectOne(new QueryWrapper<UserEntity>().eq("account", account));
        if (entity != null){
            return "该用户已经存在";
        }
        UserEntity newUser = new UserEntity();
        newUser.setAccount(account);
        newUser.setPwd(pwd);
        int insert = userDao.insert(newUser);
        return insert == 0 ? "添加失败" : "添加成功";
    }

    @PostMapping("/login")
    public String login(String account, String pwd){
        UserEntity entity = userDao.selectOne(new QueryWrapper<UserEntity>().eq("account", account)
                .eq("pwd", pwd));
        return entity != null ? "登录成功" : "登录失败";
    }

}
